<template>

  <el-dropdown trigger="click">
    <el-button type="primary" style="margin-top: 40px; margin-left: 20px">
      创建问卷<i class="el-icon-arrow-down el-icon--right"></i>
    </el-button>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item  @click="createQAgetIdApi">创建普通问卷</el-dropdown-item>
        <el-dropdown-item  divided @click="createExam">创建考试问卷</el-dropdown-item>
        <el-dropdown-item  divided @click="createSign">创建报名问卷</el-dropdown-item>
        <el-dropdown-item  divided @click="createVote">创建投票问卷</el-dropdown-item>
        <el-dropdown-item  divided @click="createCard">创建疫情打卡</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>

<!--  <el-button class="createBtn" type="primary" @click="centerDialogVisible = !centerDialogVisible">创建问卷</el-button>-->
<!--  <el-button type="primary" @click="centerDialogVisible = !centerDialogVisible"></el-button>-->

<!--  <el-dialog-->
<!--      title="请选择您的问卷类型"-->
<!--      v-model="centerDialogVisible"-->
<!--      width="20%"-->
<!--      close-on-press-escape>-->
<!--    <div><el-button type="primary" @click="createQAgetIdApi">普通问卷</el-button></div>-->
<!--    <div><el-button type="primary" @click="createExam">考试问卷</el-button></div>-->
<!--    <div><el-button type="primary" @click="createSign">报名问卷</el-button></div>-->
<!--    <div><el-button type="primary" @click="createVote">投票问卷</el-button></div>-->
<!--    <div><el-button type="primary" @click="createCard">疫情打卡</el-button></div>-->
<!--  </el-dialog>-->

</template>

<script>
import axios from "axios";
import qs from "qs";

export default {
  name: "CreateQABtn",
  data() {
    return {
      dialogVisible: false,
      centerDialogVisible: false,
    }
  },
  methods: {
    createQAgetIdApi() {
      let data = {
        id: localStorage.getItem('id'),
        type: null
      }
      axios.post('/api/qamanage/createQA',qs.stringify(data)).then(res => {
        console.log(res);
        if (res.data.code === 0) {
          let qid = res.data.data.id
          console.log(qid);
          const { href } = this.$router.resolve({
            path: '/edit',
            query: {
              questionnaireId: qid,
            }
          });
          window.open(href,'_self')
        }
      })
    },

    handleClose(done) {
    },

    // 创建考试问卷
    createExam() {
      let data = {
        id: localStorage.getItem('id'),
        type: 'exam',
      }
      axios.post('/api/qamanage/createQA',qs.stringify(data)).then(res => {
        console.log(res);
        if (res.data.code === 0) {
          let qid = res.data.data.id
          console.log(qid);
          const { href } = this.$router.resolve({
            path: '/edit/exam',
            query: {
              questionnaireId: qid,
            }
          });
          window.open(href,'_self')
        }
      })
    },

    // 创建报名问卷
    createSign() {
      let data = {
        id: localStorage.getItem('id'),
        type: 'sign',
      }
      axios.post('/api/qamanage/createQA',qs.stringify(data)).then(res => {
        console.log(res);
        if (res.data.code === 0) {
          let qid = res.data.data.id
          console.log(qid);
          const { href } = this.$router.resolve({
            path: '/edit/sign',
            query: {
              questionnaireId: qid,
            }
          });
          window.open(href,'_self')
        }
      })
    },

    // 创建投票问卷
    createVote() {
      let data = {
        id: localStorage.getItem('id'),
        type: 'vote',
      }
      axios.post('/api/qamanage/createQA',qs.stringify(data)).then(res => {
        console.log(res);
        if (res.data.code === 0) {
          let qid = res.data.data.id
          console.log(qid);
          const { href } = this.$router.resolve({
            path: '/edit/vote',
            query: {
              questionnaireId: qid,
            }
          });
          window.open(href,'_self')
        }
      })
    },

    // 创建打卡问卷
    createCard() {
      let data = {
        id: localStorage.getItem('id'),
        type: 'card',
      }
      axios.post('/api/qamanage/createQA',qs.stringify(data)).then(res => {
        console.log(res);
        if (res.data.code === 0) {
          let qid = res.data.data.id
          console.log(qid);
          const { href } = this.$router.resolve({
            path: '/edit/card',
            query: {
              questionnaireId: qid,
            }
          });
          window.open(href,'_self')
        }
      })
    }


  }
}
</script>

<style scoped>
  .createBtn {
    margin-top: 40px;
  }

  .el-button {
    color: black;
    background-color: whitesmoke;
    float: top;
    /*margin-top: 50px;*/
    /*margin-bottom: 20px;*/
  }
</style>